/*
* Copyright 2009 NOR_/D Labs <http://labs.nortd.com>
*
* This file is part of SceneExpression.
* SceneExpression is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License 
* as published by the Free Software Foundation, either version 3 of 
* the License, or (at your option) any later version. For details
* see <http://www.gnu.org/licenses/>.
*
* * *
* 
*/

#ifndef SX_VISITORS
#define SX_VISITORS


// Visitors
// see: http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials/FindingNodes

#include <osg/NodeVisitor>
#include <osg/Node>

#include "sxWidget.h"

class zIndexWidgetVisitor : public osg::NodeVisitor {
    // This visitor makes sure zIndex is set in the order
    // of rendering (depth-first traversal) for all widgets
  
    public: 
        zIndexWidgetVisitor() {
            _currentZIndex = 0;
            setTraversalMode(TRAVERSE_ALL_CHILDREN);
        }
        void reset(long startZIndex) {
            _currentZIndex = startZIndex;
        }
        // The 'apply' method for 'node' type instances.
        // Compare the 'searchForName' data member against the node's name.
        // If the strings match, add this node to our list
        virtual void apply(osg::Geode& geode) {
            sxWidget* widget = dynamic_cast<sxWidget*> (geode.getUserData());
            if( widget ) {
                //osg::notify(osg::INFO) << "applying to " << geode.getName() << endl;
                widget->setZIndex(_currentZIndex);
                _currentZIndex++;
            }
        }

    private:
        long _currentZIndex; 

};



#endif